package com.aListStream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author: Joey
 * @Description:
 * @date:2024/7/20 19:19
 */
public class StreamTest01 {

    public static void t1(){
        ArrayList<String> list = new ArrayList<>();
        list.add("张三");
        list.add("李四");
        list.add("李四as");
        list.add("李四s");
        Stream<String> stream = list.stream().filter((name) -> name.length() == 3);
        stream.forEach(System.out::println);
    }

    /**
     *  map()
     */
    public static void t2(){
        ArrayList<String> list = new ArrayList<>();
        list.add("1");
        list.add("2");
        //map()是对集合中的对象进行映射的,将对象从一种类型转换成另一种类型
                        //num -> Integer.parseInt(num)
        list.stream().map(Integer::parseInt).forEach(System.out::println);
    }

    public static void t3(){
        ArrayList<String> list = new ArrayList<>();
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        list.add("5");
        list.add("6");
        list.add("7");

        //count()对流数据进行统计   list.size()
        System.out.println(list.stream().count());
    }



    public static void main(String[] args) {

        ArrayList<String> list = new ArrayList<>();
        list.add("李四1");
        ArrayList<String> list1 = new ArrayList<>();
        list1.add("1");
//concat()实现对两个流数据进行合并
        Stream<String> stream = Stream.concat(list.stream(), list1.stream());
        List<String> list2 = stream.collect(Collectors.toList());
        System.out.println(list2);
        List<String> list3 = stream.collect(Collectors.toMap());
    }
}
